package com.ky.tms.service.impl;

import com.ky.tms.entity.TmsLinePrice;
import com.ky.tms.exception.PredictableException;
import com.ky.tms.mapper.TmsLinePriceMapper;
import com.ky.tms.service.ITmsLinePriceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ky.tms.util.RequestContextHolderUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chengkaimao
 * @since 2020-06-05
 */
@Service
public class TmsLinePriceServiceImpl extends ServiceImpl<TmsLinePriceMapper, TmsLinePrice> implements ITmsLinePriceService {

    @Autowired
    private TmsLinePriceMapper tmsLinePriceMapper;

    @Override
    public void add(TmsLinePrice tmsLinePrice) throws PredictableException {
        String userName = RequestContextHolderUtil.getUserName();
        tmsLinePrice.setIsLock(0);
        tmsLinePrice.setIsValid(1);
        tmsLinePrice.setCreateTime(LocalDateTime.now());
        tmsLinePrice.setCreateUser(userName);
        tmsLinePriceMapper.insert(tmsLinePrice);
    }

    @Override
    public void update(TmsLinePrice tmsLinePrice) throws PredictableException {
        String userName = RequestContextHolderUtil.getUserName();
        tmsLinePrice.setUpdateTime(LocalDateTime.now());
        tmsLinePrice.setUpdateUser(userName);
        tmsLinePriceMapper.updateById(tmsLinePrice);
    }
}
